package gamePackage;

//Imports
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;

public class Player {

	int x, xMove, y, yMove; //Player attributes
	Image play; //Player image variable
	int health = 100; //Player health
	int score = 0; //Player scoring (hit = 50) (kill = 200)
	int begin = 0;
	
	static ArrayList projectiles; //Projectile handler
	
	//Constructor
	public Player() {
		
		//Retrieve playable character image
		ImageIcon imgGet = new ImageIcon("src/player.png");
		play = imgGet.getImage();
		
		//Player spawn
		x = 50;
		y = 200;
		
		projectiles = new ArrayList(); //Initiate projectile handler
		
	} //End constructor
	
	public static ArrayList proList() { //Return list of projectiles to be handled
		return projectiles;
	}
	
	//Character hit detection
	public Rectangle getSize(){
		return new Rectangle(x,y, 100,77);
	}
	
	public void shoot() { //Player projectile shoot
		
		Projectile fire = new Projectile(x+155,y+55); //Projectile object
		projectiles.add(fire);
		
	} //End projectile method

	public void move() { //Move method
		
		//Add values to relocate character
		if (x + xMove <= 0) //Left border
			x = x;
		else if (x + xMove >= 800) //Right border
			x = x;
		else {
			x = x + xMove;
		}
		if (y + yMove <= 0) //Top border
			y = y;
		else if (y + yMove >= 400) //Bottom border
			y = y;
		else {
			y = y + yMove;
		}
		
	}
	
	public int playerX() { //Return x method
		
		return x;
		
	}
	
	public int playerY() { //Return y method
		
		return y;
		
	}
	
	public int isAlive() { //Return player health
		return health;
	}
	
	public int playerXMove() { //Return x move method
		
		return xMove;
		
	}
	
	public int playerYMove() { //Return y move method
		
		return yMove;
		
	}
	
	public Image getPlay() { //Return player image
		
		return play;
		
	}
	
	public void keyPressed(KeyEvent e) { //Key down method
		
		int key = e.getKeyCode(); //returns value of key pressed
		
		//Assign value to move characters to corresponding key press
		if (key == KeyEvent.VK_RIGHT) {
			xMove = 4;
		}
		if (key == KeyEvent.VK_LEFT) {
			xMove = -4;
		}
		if (key == KeyEvent.VK_UP) {
			yMove = -4;
		}
		if (key == KeyEvent.VK_DOWN) {
			yMove = 4;
		}
		if (key == KeyEvent.VK_SPACE && health > 0 && begin == 1) {
			shoot();
		}
		if (key == KeyEvent.VK_A) {
			begin = 1;
		}
	
	} //End key down method
		
	public void keyReleased(KeyEvent e) { //Key up method
			
		int key = e.getKeyCode(); //returns value of key released
			
		//Set move value to 0 if key is lifted
		if (key == KeyEvent.VK_RIGHT) {
			xMove = 0;
		}
		if (key == KeyEvent.VK_LEFT) {
			xMove = 0;
		}
		if (key == KeyEvent.VK_UP) {
			yMove = 0;
		}
		if (key == KeyEvent.VK_DOWN) {
			yMove = 0;
		}
		
	} //End key up method
	
}
